
package com.youcash.ZyWallet_spring.controller;

import com.youcash.ZyWallet_spring.entity.AdminInfo;
import com.youcash.ZyWallet_spring.service.AdminInfoService;
import com.youcash.ZyWallet_spring.utils.Base64Utils;
import com.youcash.ZyWallet_spring.vo.ResStatus;
import com.youcash.ZyWallet_spring.vo.ResultVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author Zhangzifeng
 */
@RestController
@RequestMapping("/admin")
//类注解：可以对控制器类进行详细说明
@Api(value = "提供管理员的登录和注册接口", tags = "管理员管理")
@CrossOrigin
public class AdminInfoController {
    /**
     * post: 添加
     * get: 查询
     * put: 改变
     * delete： 删除
     * option： 预检
     */
    @Resource
    private AdminInfoService adminInfoService;

    //方法注解：说明接口方法的作用
    @ApiOperation("管理员登录接口")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "string", name = "phone", value = "管理员登录手机号", required = true),
            @ApiImplicitParam(
                    dataType = "string", name = "password", value = "管理员登录密码", required = true),
    })
    @PostMapping("/login")
    public ResultVO login(@RequestParam("phone") String phone,
                          @RequestParam(value = "password") String pwd) {
        return adminInfoService.checkLogin(phone, pwd);
    }

    @ApiOperation("管理员注册接口")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "string", name = "phone", value = "管理员注册账号", required = true),
            @ApiImplicitParam(
                    dataType = "string", name = "password", value = "管理员注册密码", required = true),
    })
    @PostMapping("/register")
    public ResultVO register(@RequestBody AdminInfo adminInfo) {
        return adminInfoService.adminRegister(adminInfo.getPhone(), adminInfo.getPassword());
    }

    @ApiOperation("校验token是否过期")
    @GetMapping("/check")
    public ResultVO checkToken(@RequestHeader("token") String token){
        return new ResultVO(ResStatus.OK,"success",null);
    }

    @ApiOperation("查询个人信息接口")
    //方法注解：说明接口方法的参数
    @ApiImplicitParam(dataType = "Integer", name = "id", value = "管理员id", required = true)
    @GetMapping("/getById")
    public ResultVO getById(@RequestParam("id") Integer id) {
        return adminInfoService.getById(id);
    }
}

